package br.jcrsistemas.syscomercio.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.jcrsistemas.database.HibernateUtility;

@Entity
@Table(name = "configuracoes")
//@SequenceGenerator(name="SEQUENCE_CONFIGURACAO",sequenceName="configuracoes_id_seq")
public class Configuracao {
	@Id
//	@GeneratedValue(strategy=GenerationType.AUTO,generator="SEQUENCE_CONFIGURACAO")
//	@Column(name="id")
//	private int id;
	@Column(name="chave", length=60, unique=true)
	private String chave;
	@Column(name="valor", length=60)
	private String valor;
	public void setChave(String chave) {
		this.chave = chave;
	}
	public String getChave() {
		return chave;
	}
	public void setValor(String valor) {
		this.valor = valor;
	}
	public String getValor() {
		return valor;
	}
	
	public static void main(String[] args) {
		
		Session sessao = HibernateUtility.getSessao();
		Transaction tx = sessao.beginTransaction();
		try {
//			sessao.getTransaction().begin();
			
			Configuracao c = new Configuracao();
			c.setChave("total_comandas");
			c.setValor("1");
			sessao.save(c);
			Configuracao c2 = new Configuracao();
			c2.setChave("teste");
			c2.setValor("12");
			sessao.save(c2);
			tx.commit();
//			sessao.getTransaction().commit();
		} catch (Exception e) {
			tx.rollback();
//			sessao.getTransaction().rollback();
			e.printStackTrace();
		}
		finally {
			sessao.close();
		}
	}

}
